﻿using _11Net8AspNetCore_WebApis.BandModel;
using _11Net8AspNetCore_WebApis.Filter;
using Microsoft.AspNetCore.Builder;

namespace _11Net8AspNetCore_WebApis
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello, World!");
            // 1、创建 WebApplicationBuilder
            var build = WebApplication.CreateBuilder();

            build.Logging.AddConsole();
            // 1.1、添加控制器
            build.Services.AddControllers(option =>
            {
                // 1.1.1\ 加载CookieModelBinderProvider
                option.ModelBinderProviders.Insert(0, new CookieModelBinderProdver());

                // 1.1.2 加载MyActionFilter 
                option.Filters.Add<MyActionFilter>();

                // 1.1.3 加载LoggerActionFilter
                option.Filters.Add<LoggerMyActionFilter>();

                // 1.1.4 统一结果 
                option.Filters.Add<ResultActionFilter>();
                //option.Filters.Add<MyActionAttribute>();
            });

            build.Services.AddSingleton<MyActionAttribute>();

            // 1.2、添加Swagger
            build.Services.AddSwaggerGen();

            // 2\ 创建 webApplication
            WebApplication application = build.Build();

            //2.1 加载Swagger
            application.MapSwagger();
            application.UseSwaggerUI();

            //2.2 加载控制器
            application.MapControllers();


            // 3\运行
            application.Run();
        }
    }
}
